import 'package:cached_network_image/cached_network_image.dart';
import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:www.znpigai.teacher/global_store/state.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    AvatarState state, Dispatch dispatch, ViewService viewService) {
  List<Widget> getAvatarViews() {
    List<Widget> views = [];
    var list = GlobalState.systemConst['HeadList'];
    list.forEach((url) {
      views.add(FlatButton(
          onPressed: () => dispatch(AvatarActionCreator.onClick(url)),
          child: CachedNetworkImage(
            width: 60,
            height: 60,
            placeholder: (context, url) => CircularProgressIndicator(),
            errorWidget: (context, url, error) =>
                Image.asset("assets/images/user.png"),
            imageUrl: GlobalState.baseUrl(url),
          )));
    });
    return views;
  }

  return new Scaffold(
      appBar: new AppBar(
          centerTitle: true,
          elevation: 2.0,
          title: new Text(
            "选择头像",
            style: TextStyle(color: Colors.black54, fontSize: 18),
          )),
      body: Padding(
          padding: EdgeInsets.all(20),
          child: Wrap(
              spacing: 20.0, // gap between adjacent chips
              runSpacing: 20.0, // gap between lines
              children: getAvatarViews())));
}
